﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.Language.Intellisense;
using LuaLanguageExtension.Parsing;
using Microsoft.VisualStudio.Text;
using System.Collections.ObjectModel;
using LuaLanguageExtension.Intellisense.CompletionSets;
using LuaLanguageExtension.Parsing.Search;

namespace LuaLanguageExtension.Intellisense
{
    /// <summary>
    /// Supplies a list of completion values
    /// </summary>
    internal class CompletionSource : ICompletionSource
    {
        public CompletionSource(IObjectModelProviderBroker tokenStreamProviderBroker, ITextBuffer textBuffer)
        {
            this.textBuffer = textBuffer;
            this.tokenStreamProvider = tokenStreamProviderBroker.GetProvider(textBuffer);
        }

        /// <summary>
        /// Gets the completion information
        /// </summary>
        /// <param name="session"></param>
        /// <returns></returns>
        /// <remarks>
        /// The location of the textspan to be replaced with 
        /// the selection so that the entire word would be replaced
        /// </remarks>
        public void AugmentCompletionSession(ICompletionSession session, IList<CompletionSet> completionSets)
        {
            ObjectModelIntellisenseAcrossData acrossData = null;
            if (session.Properties.TryGetProperty<ObjectModelIntellisenseAcrossData>(typeof(ObjectModelIntellisenseAcrossData), out acrossData))
            {
                CommonCompletionSet set = new CommonCompletionSet(acrossData);
                completionSets.Add(set);
            }
        }

        public void Dispose()
        {
        }

        private ObjectModelProvider tokenStreamProvider;
        private ITextBuffer textBuffer;
    }
}
